package com.cskaoyan.controller.front;

import com.cskaoyan.bean.vo.back.BaseRespVo;
import com.cskaoyan.bean.vo.front.ShowSearchKeywordVO;
import com.cskaoyan.service.front.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 搜索
 *
 * @auther 10-何兴绕
 * @Date 2022年10月15日 09:33
 */
@RestController
@RequestMapping("wx/search")
public class SearchController {

    @Autowired
    SearchService searchService;

    /**
     * 回显搜索关键字及历史搜索关键字
     *
     * @return
     */
    @GetMapping("index")
    public BaseRespVo searchIndex() {
        ShowSearchKeywordVO showSearchKeywordVO = searchService.showSearchKeyword();
        return BaseRespVo.ok(showSearchKeywordVO);
    }

    /**
     * 回显搜索时的关键字
     * @param keyword
     * @return
     */
    @GetMapping("helper")
    public BaseRespVo searchKey(String keyword) {
        List<String> strings = searchService.searchKeys(keyword);
        return BaseRespVo.ok(strings);
    }

    /**
     * 清除搜索历史
     * @return
     */
    @PostMapping("clearhistory")
    public BaseRespVo clearHistory(){
        searchService.clearHistory();
        return BaseRespVo.ok();
    }
}
